<?php session_start();
$_SESSION["previouspage"] = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];//remember the url of this page, used for redirect.
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="third_party/jquery-ui-1.8.5/jquery-ui-1.8.5.custom.css" />
<link rel="stylesheet" type="text/css" href="css/template.css" />
<link rel="stylesheet" type="text/css" href="css/home.css" /> 
<script type="text/javascript" src="js/system.js"></script>
<script type="text/javascript" src="third_party/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="third_party/jquery-ui-1.8.5/jquery-ui-1.8.5.custom.min.js"></script>
<script type="text/javascript" src="third_party/jquery.tmpl.min.js"></script>
<script type="text/javascript" src="js/network.js"></script>
<script type="text/javascript" src="js/system.js"></script>
<script id="list-template" type="text/x-jquery-tmpl"> 
<li><a href="paper_view.php?id=${ID}">${TITLE}</a>&nbsp;(${COUNT})</li>
</script>
<script id="paper-result-template" type="text/x-jquery-tmpl"> 
<li>
	<small class="right">resources: ${RES_COUNT}<br />views: ${READ_COUNT}<br />reviews: ${RATE_COUNT}</small>
	<a href="paper_view.php?id=${ID}">${TITLE}</a>
	<p>${ABSTRACT}</p>
	<span>${URL}</span>
</li>
</script>
<script id="person-result-template" type="text/x-jquery-tmpl"> 
<li>
	<a href="person_view.php?id=${ID}">${USERNAME}</a>
	<p>${DESCRIPTION}</p>
	
</li>
</script>
<script type="text/javascript">
function SubmitForm(form) {
	RequestData("search.php", $(form).serialize(), UpdateResult);
}

function UpdateResult(data) {
	var template = "#" + data["type"] + "-result-template";
	$("#result-log").text(data["type"] + " search: " + data["count"] + " result(s) (" + data["time"] + " seconds)");
	$("#result").empty();
	$(template).tmpl(data["result"]).appendTo("#result");
}

//tabs must be defined here
$(function() {
	$("input.date").datepicker();
	$("#tabs").tabs();
	$("input.button").button();
	RequestData("search.php", { type: "paper", preset: "read" },
							function(data) { $("#list-template").tmpl(data["result"]).appendTo("#most-read-papers"); });
	RequestData("search.php", { type: "paper", preset: "reviewed" },
							function(data) { $("#list-template").tmpl(data["result"]).appendTo("#most-reviewed-papers"); });
	RequestData("search.php", { type: "paper", preset: "annotated" },
							function(data) { $("#list-template").tmpl(data["result"]).appendTo("#most-annotated-papers"); });
});
</script>

<title>Search - CoRAL</title>
</head>
<body>

<?php //to determine whether a user has logged in or not, which will output different buttons
if(isset($_SESSION["accountNo"]))	{	$inorout = "controller/logout.php";	$display = "Log out";}
else	{	$inorout = "login.php";	$display = "Log in";}
?>

<div id="body-wrapper">
<?php include_once 'static/header.php'; ?>
	<div id="body">
	
		<!-- START SECTION: search -->
		<div id="search-section" class="section" >
			<div id="tabs" style="overflow:hidden;"> 
				<ul>
					<li><a href="#tabs-1"><strong>Paper Search</strong></a></li>
					<li><a href="#tabs-2"><strong>Person Search</strong></a></li>
				</ul>
				<div id="tabs-1"> <!-- Paper Search-->
					<div id="textSearch" style="display:block"> <!-- Basic text search (one field)-->
						<a class = "section" onclick="javascript:showElement('advancedSearch'); javascript:showElement('textSearch')">Advanced Search</a>
						<form id="paperTextSearch" onsubmit="SubmitForm(this); return false;">
							<input type="hidden"  name="type" value="paper" />
							<table class="info">
								<tr><td class="labelright"><strong>Text Search: </strong></td><td><input name="q" type="text" size="60" colspan="2" /></td></tr>
								<tr><td class="labelright"><strong>Search for: </strong></td>
									<td>
										Title <input name="includetitle" type="checkbox" value="Title" />&nbsp;&nbsp;&nbsp;&nbsp;
										Abstract <input name="includeabstract" type="checkbox" value="Abstract" />&nbsp;&nbsp;&nbsp;&nbsp;
										Tags <input name="includetags" type="checkbox" value="Tags" />&nbsp;&nbsp;&nbsp;&nbsp;
										Author(s) <input name="includeauthor" type="checkbox" value="Author" />
									</td>
								</tr>&nbsp;&nbsp;&nbsp;&nbsp;
							</table>
							<tr><th></th></tr>
							<input type="submit" class="button" value="Search" />
						</form>
										<div id="cal1Container"></div> 
					</div>
	
					<div id="advancedSearch" style="display:none">  <!-- Advanced text search (multiple fields)-->
						<a class = "section" onclick="javascript:showElement('advancedSearch'); javascript:showElement('textSearch')">Text Search</a>
						<form id="paperAdvancedSearch" onsubmit="SubmitForm(this); return false;">
							<input type="hidden"  name="type" value="advancedpaper" />
							<table class="info">
								
	                            <tr>
	                            	<td class="labelright"><strong>Title: </strong></td><td colspan="5"><input name="titlesearch" type="text" size="60" /></td>
	                            </tr>
	                            <tr>
	                            	<td class="labelright"><strong>Abstract: </strong></td><td colspan="5"><input name="abstractsearch" type="text" size="60" /></td>
	                            </tr>
	                            <tr>
	                            	<td class="labelright"><strong>Tags: </strong></td><td colspan="5"><input name="tagsearch" type="text" size="60" /></td>
	                            </tr>
	                            <tr>
	                            	<td class="labelright"><strong>Author(s): </strong></td><td colspan="5"><input name="authorsearch" type="text" size="60" /></td>
	                            </tr>
	                            <tr>
	                            	<td class="labelright" width="120px"><strong>Year of Publication: </strong></td>
	                           		<td width="120px"><input name="yearsearch" type="text" size="20" /></td>
	                            	<td width="50px"></td>
	                            	<td class="labelright" width="73px"><strong>Rating: </strong></td>
	                             	<td width="120px">
		                            	<select name="ratingdropdown">
		                                	<option value="4+"> 4+ </option>
		                                	<option value="4"> 4 </option>
		                                  	<option value="3+"> 3+ </option>
		                                 	<option value="3"> 3 </option>
		                                   	<option value="2+"> 2+ </option>
		                                   	<option value="2"> 2 </option>
		                                  	<option value="1+"> 1+ </option>
		                                  	<option value="1"> 1 </option>
		                               	</select>
									</td>
	                            </tr>
								<tr>
									<td class="labelright" width="120px"><strong>ISBN: </strong></td><td width="120px"><input name="isbnsearch" type="text" size="20" /></td>
								 	<td width="50px"></td>
								 	<td class="labelright" width="73px"><strong>DOI: </strong></td><td width="250px"><input name="doisearch" type="text" size="18" /></td>
								
									<td width="300px"></td>
								</tr>
								
	                         	<tr>
	                         		<td class="labelright"><strong>Journal: </strong></td><td colspan="5"><input name="journalsearch" type="text" size="60"/></td>
	                         	</tr>
	                        </table>
							<input type="submit" class="button" value="Search" />
						</form>
					</div>
				</div> 
				
				<div id="tabs-2">  <!-- Person Search -->
					<form id="personSearch" onsubmit="SubmitForm(this); return false;">
						<input type="hidden"  name="type" value="person" />
						<table class="info">
							<tr>
							 	<th colspan="5"><font size="1"><?php echo "Note that if a user has selected to mark some information as 'private', they may not be returned in search results"; ?></font></th>
							</tr>
							<tr>
								<td class="labelright"><strong>Name: </strong></td><td colspan="5"><input name="textsearch" type="text" size="60" colspan="2"  /></td>
							</tr>
							<tr>
								<td class="labelright"><strong>Affiliation: </strong></td><td colspan="5"><input name="textsearch" type="text" size="60" colspan="2"  /></td>
							</tr>
							<tr>
								<td class="labelright"><strong>E-mail: </strong></td><td colspan="5"><input name="textsearch" type="text" size="60" colspan="2"  /></td>
							</tr>
								<tr>
									<td class="labelright" width="120px"><strong>Join Date: </strong></td><td width="120px"><input name="joindate" id="cal1Date" type="text" size="20" /></td>
								 	<td width="40px"></td>
								 	<td class="labelright" width="73px"><strong>Community Score: </strong></td><td width="250px"><input name="communityscore" type="text" size="16" /></td>
								 	<td width="300px"></td>
								</tr>
							<tr><th>	
						</table>
						<input type="submit" class="button" value="Search" />
					</form>
					<div id="cal1Container"></div> 
				</div>
			</div>
		</div>
		<!-- END SECTION: search -->
		
		<!-- START SECTION: result -->
		<div id="result-section" class="section"><span id="result-log"></span><ul id="result"></ul></div>
		<!-- END SECTION: result -->
	</div>
	<?php include_once 'static/footer.html'; ?>
	</div>
	</body>
</html>
